﻿using M6R小圆柱注液机.Data;
using M6R小圆柱注液机.Pages;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FastData;
using System.Control;
using System.IO;
using M6R小圆柱注液机.TaskList;

namespace M6R小圆柱注液机
{
    public partial class FormMain : Form
    {
        private Button buttonCurrentSelected = new Button();
        StartControl.Welcom welcom = new StartControl.Welcom();
        Timer OpacyTimer = new Timer();
        public FormMain()
        {
            OpacyTimer.Tick += new EventHandler(OpacyTimer_Tick);
            OpacyTimer.Interval = 20;
            //welcom.Start();
            Opacity = 0;
            InitializeComponent();
            OpacyTimer.Start();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            GlobalValues.InitCheckFileExit();//创建文件夹和文件 - -  初始化
            GlobalValues.InitGlobalVariableValue();//全局变量 - -  初始化
            GlobalValues.mysql_Helper.SqlConn(GlobalValues.PathVariable.dataBasePath);//连接数据库 - - 初始化
            MainPageInit();//主界面控件 - -  初始化
            MountEventInit();  //挂在事件 - -  初始化
            TimerStartInit();//主界面Timer启动
            btnHome_Click(btnHome, new EventArgs());
            Task ProductDataAcqTask = new Task(GlobalValues.productDataAcq.Init, TaskCreationOptions.LongRunning);
            ProductDataAcqTask.Start();
            //welcom.Stop();
        }



        private void OpacyTimer_Tick(object sender, EventArgs e)
        {
            if (Opacity >= 1)
            {
                OpacyTimer.Stop();
                OpacyTimer.Tick -= new EventHandler(OpacyTimer_Tick);
            }
            else
            {
                Opacity += 0.2;
            }
        }


        /// <summary>
        /// 主界面控件初始化
        /// </summary>
        private void MainPageInit()
        {
            //运行程序按钮，开机默认不可用，直到初始化完成，才解锁该空间
            btnStart.Enabled = false;
            ////先隐藏CPK界面
            //lbHideCPK_MouseDoubleClick(lbHideCPK, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 2));
            panel6.Size = new Size(983, 154);
            //程序版本
            lbProgramVersion.Text = SaveStatic.ReadIni(GlobalValues.PathVariable.fileCommonPara, "Machine_Para", "ProgramVersion");


            //用户登录信息
            lbUserName.Text = "-";
            lbUserLoginStatus.Text = "未验证";
            lbUserLoginStatus.ForeColor = Color.Red;
            //成品编码信息
            lbFinishedProductCoding.Text = "-";
            lbFinishedProductCodingCheckStatus.Text = "未验证";
            lbFinishedProductCodingCheckStatus.ForeColor = Color.Red;
            //电解液信息
            lbElectrolyteNumber.Text = "-";
            lbElectrolyteCheckStatus.Text = "未验证";
            lbElectrolyteCheckStatus.ForeColor = Color.Red;
            //班次
            lbShift.Text = "-";
            //设备号
            lbMachineNumber.Text = "-";



            //电池、注液重量范围
            lbBatteryWeightMin.Text = GlobalValues.CommonVariable.BatteryWeightMin.ToString();
            lbBatteryWeightMax.Text = GlobalValues.CommonVariable.BatteryWeightMax.ToString();
            lbNoteLiquidWeightMin.Text = GlobalValues.CommonVariable.NoteLiquidWeightMin.ToString();
            lbNoteLiquidWeightMax.Text = GlobalValues.CommonVariable.NoteLiquidWeightMax.ToString();
            //周次
            cbWeekTime.Checked = true;
            nudWeekTime.Enabled = false;
            nudWeekTime.Value = int.Parse(SaveStatic.ReadIni(GlobalValues.PathVariable.fileCommonPara, "MainPage_Para", "WeekTime"));
            //条码前几位
            cbCodeTop.Checked = true;
            tbCodeTop.Enabled = false;
            tbCodeTop.Text = SaveStatic.ReadIni(GlobalValues.PathVariable.fileCommonPara, "MainPage_Para", "CodeTop");
        }






        /// <summary>
        /// 挂载事件
        /// </summary>
        private void MountEventInit()
        {
            //主界面Log信息显示事件
            GlobalValues.log_Helper.eventDispProcess += Log_Helper_eventDispProcess;
            //点检界面的事件
            GlobalValues.pointCheck.eventFrontWeightCheckResult += PointCheck_eventFrontWeightCheckResult1;
            GlobalValues.pointCheck.eventBehindWeightCheckResult += PointCheck_eventBehindWeightCheckResult1;
            //设置界面的事件
            GlobalValues.settingPage.eventChangingInfomation_SettingPage += SettingPage_eventChangingInfomation_SettingPage;
            //数据采集类，表示流程初始化完成，允许启动程序的事件
            GlobalValues.productDataAcq.eventAllowStartProgram += ProductDataAcq_eventAllowStartProgram;
            GlobalValues.productDataAcq.eventFormToMainForm += ProductDataAcq_eventFormToMainForm;
        }


        //Log--事件
        private void Log_Helper_eventDispProcess(string msg, Color ForeColor)
        {
            this.BeginInvoke(new EventHandler(delegate
            {
                updataRichText(txtProcessDisp, 100);
                //txtProcessDisp.Focus();
                txtProcessDisp.SelectionColor = ForeColor;
                txtProcessDisp.AppendText(msg);
                //滚动条到最下面
                txtProcessDisp.Select(txtProcessDisp.Text.Length, 0);
                txtProcessDisp.ScrollToCaret();
            }));
        }

        /// <summary>
        /// 限制richTextbox的行数
        /// </summary>
        /// <param name="richTextBox"></param>
        /// <param name="maxLinds"></param>
        private void updataRichText(System.Windows.Forms.RichTextBox richTextBox, int maxLinds)
        {

            if (richTextBox.Lines.Length >= maxLinds)
            {
                richTextBox.SelectionStart = 0;
                richTextBox.SelectionLength = richTextBox.Text.IndexOf("\n") + 1;
                richTextBox.SelectedText = "";
                //光标聚焦在最后一行
                richTextBox.Select(richTextBox.Text.Length, 0);
                richTextBox.ScrollToCaret();
            }
        }

        //前电子秤点检结果
        private void PointCheck_eventFrontWeightCheckResult1(float result_1, float result_2, bool value1, bool value2)
        {
            this.Invoke(new EventHandler(delegate
            {
                lbWeight_1CheckResult.Text = result_1.ToString();
                lbWeight_2CheckResult.Text = result_2.ToString();
                if (value1) { lbWeight_1CheckResult.ForeColor = Color.Green; }
                else { lbWeight_1CheckResult.ForeColor = Color.Red; }
                if (value2) { lbWeight_2CheckResult.ForeColor = Color.Green; }
                else { lbWeight_2CheckResult.ForeColor = Color.Red; }
            }));

        }

        //后电子秤点检结果
        private void PointCheck_eventBehindWeightCheckResult1(float result_3, float result_4, bool value3, bool value4)
        {
            this.Invoke(new EventHandler(delegate
            {
                lbWeight_3CheckResult.Text = result_3.ToString();
                lbWeight_4CheckResult.Text = result_4.ToString();
                if (value3) { lbWeight_3CheckResult.ForeColor = Color.Green; }
                else { lbWeight_3CheckResult.ForeColor = Color.Red; }
                if (value4) { lbWeight_4CheckResult.ForeColor = Color.Green; }
                else { lbWeight_4CheckResult.ForeColor = Color.Red; }
            }));

        }



        /// <summary>
        /// 周次 勾选事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbWeekTime_CheckedChanged(object sender, EventArgs e)
        {
            if (cbWeekTime.Checked)
            {
                nudWeekTime.Enabled = false;
                SaveStatic.SaveIni(GlobalValues.PathVariable.fileCommonPara, "MainPage_Para", "WeekTime", nudWeekTime.Value.ToString());
            }
            else
            {
                nudWeekTime.Enabled = true;
                nudWeekTime.Value = int.Parse(SaveStatic.ReadIni(GlobalValues.PathVariable.fileCommonPara, "MainPage_Para", "WeekTime"));
            }
        }

        /// <summary>
        /// 条码前几位 勾选事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbCodeTop_CheckedChanged(object sender, EventArgs e)
        {
            if (cbCodeTop.Checked)
            {
                tbCodeTop.Enabled = false;
                SaveStatic.SaveIni(GlobalValues.PathVariable.fileCommonPara, "MainPage_Para", "CodeTop", tbCodeTop.Text);
            }
            else
            {
                tbCodeTop.Enabled = true;
                tbCodeTop.Text = SaveStatic.ReadIni(GlobalValues.PathVariable.fileCommonPara, "MainPage_Para", "CodeTop");
            }
        }

        //设置界面的事件,显示修改值的事件
        private void SettingPage_eventChangingInfomation_SettingPage(string msg, int num)
        {
            switch (num)
            {
                case 0:
                    //砝码重量
                    break;
                case 1:
                    //误差值
                    break;
                case 2:
                    GlobalValues.CommonVariable.mechineInfo = msg;//设备号
                    break;
                case 3:
                    lbProgramVersion.Text = msg;//程序版本
                    break;
                case 4:
                    //电解液批次号前几位
                    break;
                case 5:
                    //注液量的闭环周期
                    break;
                default:
                    break;
            }
        }

        //数据类，初始化流程完成触发的事件
        private void ProductDataAcq_eventAllowStartProgram(bool status)
        {
            this.Invoke(new EventHandler(delegate
            {
                GlobalValues.mainPage.ReadOnceDataBase();//读取一次数据库的数据，显示到主界面上
                btnStart.Enabled = true;
            }));
        }
        /// <summary>
        /// 数据类  弹窗
        /// </summary>
        /// <param name="form"></param>

        private void ProductDataAcq_eventFormToMainForm(Form form)
        {
            this.Invoke(new EventHandler(delegate { form.ShowDialog(); }));
        }

        /// <summary>
        /// 刷新主界面控件信息的Timer事件
        /// </summary>
        private void TimerStartInit()
        {
            //主界面信息刷新
            Timer tMainFlash = new Timer();
            tMainFlash.Interval = 1000;
            tMainFlash.Tick += TMainFlash_Tick;
            tMainFlash.Start();

            //界面权限刷新
            Timer tLimit = new Timer();
            tLimit.Interval = 1000;
            tLimit.Tick += TLimit_Tick;
            tLimit.Start();
        }


        private void TimerCPKFlash()
        {
            //CPK信息刷新
            Timer tCPK = new Timer();
            tCPK.Interval = 1000;
            tCPK.Tick += tCPK_Tick;
            tCPK.Start();
            //CPK补偿值刷新
            Timer tCPKOffset = new Timer();
            tCPKOffset.Interval = 1000;
            tCPKOffset.Tick += tCPKOffset_Tick;
            tCPKOffset.Start();
        }

        private void TimerHeart()
        {
            //CPK补偿值刷新
            Timer tHeart = new Timer();
            tHeart.Interval = 500;
            tHeart.Tick += THeart_Tick;
            tHeart.Start();
        }


        private void btnHome_Click(object sender, EventArgs e)
        {
            ShowForm(splitContainer1.Panel1, GlobalValues.mainPage);
            ButtonSelected(buttonCurrentSelected, btnHome);
        }

        private void btnSetting_Click(object sender, EventArgs e)
        {
            ShowForm(splitContainer1.Panel1, GlobalValues.settingPage);
            ButtonSelected(buttonCurrentSelected, btnSetting);
        }

        private void btnProductData_Click(object sender, EventArgs e)
        {
            ShowForm(splitContainer1.Panel1, GlobalValues.productInquiryPage);
            ButtonSelected(buttonCurrentSelected, btnProductData);
        }

        private void btnAlarm_Click(object sender, EventArgs e)
        {
            ShowForm(splitContainer1.Panel1, GlobalValues.alarmInquiryPage);
            ButtonSelected(buttonCurrentSelected, btnAlarm);
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            AdminLoginPage admin = new AdminLoginPage();
            ButtonSelected(buttonCurrentSelected, btnLogin);//控件颜色选中        
            admin.ShowDialog();//显示界面          
            admin.Dispose();//
        }

        private void btnChart_Click(object sender, EventArgs e)
        {
            ShowForm(splitContainer1.Panel1, GlobalValues.chartPage);
            ButtonSelected(buttonCurrentSelected, btnChart);
        }

        private void btnModeChange_Click(object sender, EventArgs e)
        {
            ButtonSelected(buttonCurrentSelected, btnModeChange);
            ModePage mode = new ModePage();
            mode.ShowDialog();
            mode.Dispose();
        }


        /// <summary>
        /// 启动程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (GlobalValues.StatusVariable.status_AllowStartProgarm)
            {
                GlobalValues.StatusVariable.status_AutoRunning = true;
                GlobalValues.productDataAcq.StartProductDataAutoTask();//自动运行的线程、PLC监测的线程启动
                GlobalValues.alarmAcq.StartAlarmAutoTask();//启动报警线程
                btnStart.BackColor = Color.LightPink;
                btnStart.Enabled = false;
                TimerCPKFlash();//启动CPK 的刷新timer
                TimerHeart();//PLC心跳
            }
            else
            {

            }

        }


        private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult dr = MessageBox.Show("确认退出当前程序？", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dr == DialogResult.Yes)
            {
                GlobalValues.StatusVariable.status_AutoRunning = false;
                bool canClose = false;
                while (!canClose)
                {
                    if (ProductDataAcq.weightForntDataAll.Count <= 0 && ProductDataAcq.weightBehindDataAll.Count <= 0)
                    {
                        //确保数据存储完成，再退出程序
                        LogOut();//退出程序前，执行的注销内容
                        canClose = true;
                    }
                    Thread.Sleep(200);
                }
            }
            else
            {
                e.Cancel = true;//取消本次事件
            }
        }


        /// <summary>
        /// 退出程序前，需要执行的注销事件
        /// </summary>
        private void LogOut()
        {
            //关闭所有的Timer


            //电子秤注销
            GlobalValues.Fore_And1.PowerOFF();
            GlobalValues.Fore_And2.PowerOFF();
            GlobalValues.Behind_And1.PowerOFF();
            GlobalValues.Behind_And2.PowerOFF();


            //电子秤的串口关闭
            GlobalValues.serialPort1.Close();
            GlobalValues.serialPort2.Close();
            GlobalValues.serialPort3.Close();
            GlobalValues.serialPort4.Close();
            //MFG注销
            GlobalValues.serialPort5.Close();
            //扫码枪注销
            GlobalValues.newScanner_1.StopReceivingMessage();//关闭监听
            GlobalValues.newScanner_1.DisConnect();//关闭连接
            GlobalValues.newScanner_2.StopReceivingMessage(); //关闭监听 
            GlobalValues.newScanner_2.DisConnect();//关闭连接
            GlobalValues.newScanner_3.StopReceivingMessage();//关闭监听
            GlobalValues.newScanner_3.DisConnect();//关闭连接


            //数据库注销
            if (GlobalValues.mysql_Helper.CheckStates()) { GlobalValues.mysql_Helper.SqlClose(); }

            //关闭PLC的服务
            GlobalValues.njOmronPLC.StopPLCService(5000);
        }

        /// <summary>
        /// 显示CPK数据的界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnShowCPK_Click(object sender, EventArgs e)
        {
            if (tableLayoutPanel1.Visible == true) { return; }
            else
            {
                tableLayoutPanel1.Visible = true;
                panel6.Size = new Size(983, 248);
            }
        }
        /// <summary>
        /// 隐藏CPK数据的界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lbHideCPK_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (tableLayoutPanel1.Visible == false) { return; }
            else
            {
                tableLayoutPanel1.Visible = false;
                panel6.Size = new Size(983, 154);
            }
        }

        public void ShowForm(System.Windows.Forms.Panel panel, System.Windows.Forms.Form frm)
        {
            if (panel.Controls.Contains(frm))
            {
                return;
            }
            else
            {
                if (panel.Controls.Count > 0)
                {
                    Form f = (Form)panel.Controls[0];
                    f.Hide();
                }
                frm.TopLevel = false;
                frm.Dock = System.Windows.Forms.DockStyle.Fill;
                frm.FormBorderStyle = FormBorderStyle.None;
                panel.Controls.Clear();
                panel.Controls.Add(frm);
                frm.Show();
                //按钮颜色变为选中
                //button.BackColor = Color.FromArgb(211, 211, 211);
                //其他的按钮变为未选中的颜色（235,235,235）
            }
        }
        //改变按钮颜色变为选中颜色
        private void ButtonSelected(Button currentButton, Button nextButton)
        {
            if (nextButton == currentButton)
            {
                return;
            }
            else
            {
                if (currentButton != null)
                {
                    currentButton.BackColor = Color.FromArgb(200, 200, 200);
                }
                nextButton.BackColor = Color.LightPink;
                buttonCurrentSelected = nextButton;
            }
        }

        private void btnWeight_1Clear_Click(object sender, EventArgs e)
        {
            GlobalValues.Fore_And1.ZeroV();
        }

        private void btnWeight_3Clear_Click(object sender, EventArgs e)
        {
            GlobalValues.Fore_And2.ZeroV();
        }

        private void btnWeight_2Clear_Click(object sender, EventArgs e)
        {
            GlobalValues.Behind_And1.ZeroV();
        }

        private void btnWeight_4Clear_Click(object sender, EventArgs e)
        {
            GlobalValues.Behind_And2.ZeroV();
        }


        /// <summary>
        /// 更换电解液
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnChangeElectrolyte_Click(object sender, EventArgs e)
        {
            //启动线程，用于与MFG的交互
            Task tak = new Task(new Action(() =>
            {
                string Ret = "";
                DialogResult ret = MessageBox.Show("确认发送ESN到电解液房以获取或更新电解液号？", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0);
                if (ret == DialogResult.OK)
                {
                    this.BeginInvoke(new Action(() =>
                    {
                        //清空文件中已保存的电解液批次后，防止电解液验证失败，程序会继续读取上一次的电解液信息进行生产！！
                        string ElectrolyteNumber_FileToClear = "000000000000000000";
                        SaveStatic.SaveIni(GlobalValues.PathVariable.fileCommonPara, "Machine_Para", "ElectrolyteBatch", ElectrolyteNumber_FileToClear);

                        //显示界面                   
                        GlobalValues.electrolyteChangingPage = new ElectrolyteChangingPage();//创建实例
                        GlobalValues.electrolyteChangingPage.ShowDialog();//打开 更换电解液界面

                    }));

                    GlobalValues.log_Helper.DispProcess("更换电解液中 . . . ", "Info", true);//log

                    try
                    {
                        GlobalValues.serialPort5.SendMessage("ESN");
                        Thread.Sleep(1000);
                        Ret = GlobalValues.serialPort5.SendBackMessageInstant("ESN", 1000 * 60 * 10);//延时10分钟

                        string newFinishedProductCoding = Ret.Split(',')[2];//新的成品编码
                        string newElectrolyteNumber = Ret.Split(',')[3];//新的电解液批次号

                        //确认无聊编码是否正确
                        if (lbFinishedProductCoding.Text != newFinishedProductCoding)
                        {
                            GlobalValues.log_Helper.DispProcess("更换电解液过程中，成品编码信息不一致！新成品编码为：" + newFinishedProductCoding, "Alarm", true);//log

                            //把异常反馈给PLC
                            //OmroPLCvar.WriteSingleVarible(PLC扫描.PLC扫电芯码数据内存名称[1], 8);

                            //关闭更换电解液的界面,并释放资源
                            GlobalValues.electrolyteChangingPage.Close();
                            GlobalValues.electrolyteChangingPage.Dispose();
                            return;
                        }

                        //判断读取上来的电解液批次号是否包含 配置文件中保存的电解液批次号前几位，以此确认读取上来的电解液批次号的正确性
                        if (newElectrolyteNumber.Contains(SaveStatic.ReadIni(GlobalValues.PathVariable.fileCommonPara, "Machine_Para", "ElectrolyteBatchFrontSerialNumber")))
                        {
                            lbElectrolyteNumber.Text = newElectrolyteNumber;//批次号显示到主界面
                                                                            //参数保存到文件
                            SaveStatic.SaveIni(GlobalValues.PathVariable.fileCommonPara, "Machine_Para", "FinishedProductCoding", newFinishedProductCoding);//成品编码
                            SaveStatic.SaveIni(GlobalValues.PathVariable.fileCommonPara, "Machine_Para", "ElectrolyteBatch", newElectrolyteNumber);//电解液批次号
                            GlobalValues.log_Helper.DispProcess("电解液更换成功！" + "\r\n" + "物料编码:" + newFinishedProductCoding + "；电解液号:" + newElectrolyteNumber, "Info", true);
                        }
                        else
                        {
                            ////报错，把信息反馈给PLC
                            //OmroPLCvar.WriteSingleVarible("PcRepetition", -1);
                            GlobalValues.log_Helper.DispProcess("新电解液信息前几位不匹配，请检查！！" + "\r\n" + "当前批次号为：" + newElectrolyteNumber, "Alarm", true);
                        }
                    }
                    catch
                    {
                        if (Ret == null)
                        {
                            //////报错，把信息反馈给PLC
                            //OmroPLCvar.WriteSingleVarible("PcRepetition", -2);
                            GlobalValues.log_Helper.DispProcess("获取到电解液信息，更换电解液超时！", "Alarm", true);
                        }
                        else
                        {
                            //////报错，把信息反馈给PLC
                            //OmroPLCvar.WriteSingleVarible("PcRepetition", -3);
                            GlobalValues.log_Helper.DispProcess("电解液信息不合法！", "Alarm", true);
                        }
                    }
                    //关闭窗口界面
                    this.Invoke(new Action(() =>
        {
            GlobalValues.electrolyteChangingPage.Close();
            GlobalValues.electrolyteChangingPage.Dispose();
        }));
                }
            }), TaskCreationOptions.LongRunning);
            tak.Start();
        }


        /// <summary>
        /// 主界面控件信息刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TMainFlash_Tick(object sender, EventArgs e)
        {
            //操作员名称
            if (GlobalValues.CommonVariable.operatorNameInfo != "-")
            {
                lbUserName.Text = GlobalValues.CommonVariable.operatorNameInfo;
                lbUserLoginStatus.Text = "已登录";
                lbUserLoginStatus.ForeColor = Color.Green;
            }
            else
            {
                lbUserLoginStatus.Text = "未登录";
                lbUserLoginStatus.ForeColor = Color.Red;
            }
            //成品编码
            if (GlobalValues.CommonVariable.finishedProductCodingInfo != "-")
            {
                lbFinishedProductCoding.Text = GlobalValues.CommonVariable.finishedProductCodingInfo;
                lbFinishedProductCodingCheckStatus.Text = "已验证";
                lbFinishedProductCodingCheckStatus.ForeColor = Color.Green;
            }
            else
            {
                lbFinishedProductCodingCheckStatus.Text = "未验证";
                lbFinishedProductCodingCheckStatus.ForeColor = Color.Red;
            }
            //电解液号
            if (GlobalValues.CommonVariable.electrolyteNumberInfo != "-")
            {
                lbElectrolyteNumber.Text = GlobalValues.CommonVariable.electrolyteNumberInfo;
                lbElectrolyteCheckStatus.Text = "已验证";
                lbElectrolyteCheckStatus.ForeColor = Color.Green;
            }
            else
            {
                lbElectrolyteCheckStatus.Text = "未验证";
                lbElectrolyteCheckStatus.ForeColor = Color.Red;
            }
            //班次        
            lbShift.Text = GlobalValues.CommonVariable.shiftInfo;
            //设备号
            lbMachineNumber.Text = GlobalValues.CommonVariable.mechineInfo;

            if (GlobalValues.StatusVariable.isStartGRR)
            {
                panel4.BackColor = Color.Yellow;
                lbGRRStatus.Visible = true;
            }
            else
            {
                panel4.BackColor = Color.White;
                lbGRRStatus.Visible = false;
            }
        }


        bool heartSym = false;
        /// <summary>
        /// 心跳信号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void THeart_Tick(object sender, EventArgs e)
        {
            if (heartSym)
            {
                GlobalValues.njOmronPLC.WriteVariable("K_height_online", 1);//反馈接收信息
                heartSym = false;
            }
            else
            {
                GlobalValues.njOmronPLC.WriteVariable("K_height_online", 0);//反馈接收信息
                heartSym = true;
            }
            //if (GlobalValues.om.IsConnected) { GlobalValues.log_Helper.DispProcess("PLC断开连接，请检查", "Alarm", true); }//PLC的连接状态
        }


        /// <summary>
        /// 权限管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TLimit_Tick(object sender, EventArgs e)
        {
            if (GlobalValues.StatusVariable.isAdminLoginSuccess)
            {
                btnShowCPK.Enabled = true;
                btnClearCPKOffset.Enabled = true;
                btnClearCPK.Enabled = true;
                btnWeight_1Clear.Enabled = true;
                btnWeight_2Clear.Enabled = true;
                btnWeight_3Clear.Enabled = true;
                btnWeight_4Clear.Enabled = true;
                btnModeChange.Visible = true;
            }
            else if (GlobalValues.StatusVariable.isEngineerLoginSuccess)
            {
                btnShowCPK.Enabled = true;
                btnClearCPKOffset.Enabled = true;
                btnClearCPK.Enabled = true;
                btnWeight_1Clear.Enabled = true;
                btnWeight_2Clear.Enabled = true;
                btnWeight_3Clear.Enabled = true;
                btnWeight_4Clear.Enabled = true;
                btnModeChange.Visible = true;
            }
            else
            {
                btnShowCPK.Enabled = false;
                btnClearCPKOffset.Enabled = false;
                btnClearCPK.Enabled = false;
                btnWeight_1Clear.Enabled = false;
                btnWeight_2Clear.Enabled = false;
                btnWeight_3Clear.Enabled = false;
                btnWeight_4Clear.Enabled = false;
                btnModeChange.Visible = false;
            }
        }




        public static double zhuye_min = 1;
        public static double zhuye_max = 1.2;
        float[] cpklist1;
        float[] cpklist2;
        float[] cpklist3;
        float[] cpklist4;
        float[] cpklist5;
        float[] cpklist6;
        float cpk1 = 0, cpk2 = 0, cpk3 = 0, cpk4 = 0, cpk5 = 0, cpk6 = 0;


        CpkPro cpkpro = new CpkPro();

        private void tCPK_Tick(object sender, EventArgs e)
        {
            try
            {
                //CPK  
                //针头1_1
                if (!File.Exists(GlobalValues.PathVariable.fileCPK_1))
                {
                    lbCPKValue_1.Text = "-";
                }
                else
                {
                    cpklist1 = Array.ConvertAll(SaveStatic.ReadTxt(GlobalValues.PathVariable.fileCPK_1), Convert.ToSingle);
                    if (cpklist1.Count() > 2)
                    {
                        cpk1 = cpkpro.GetCPK(cpklist1, (float)zhuye_max, (float)zhuye_min);
                    }
                    else
                        cpk1 = 0;
                    lbCPKValue_1.Text = cpk1.ToString("0.000");
                }

                //针头1_2
                if (!File.Exists(GlobalValues.PathVariable.fileCPK_2))
                {
                    lbCPKValue_2.Text = "-";
                }
                else
                {
                    cpklist2 = Array.ConvertAll(SaveStatic.ReadTxt(GlobalValues.PathVariable.fileCPK_2), Convert.ToSingle);
                    if (cpklist2.Count() > 2)
                    {
                        cpk2 = cpkpro.GetCPK(cpklist2, (float)zhuye_max, (float)zhuye_min);
                    }
                    else
                        cpk2 = 0;
                    lbCPKValue_2.Text = cpk2.ToString("0.000");
                }




                //针头2_1
                if (!File.Exists(GlobalValues.PathVariable.fileCPK_3))
                {
                    lbCPKValue_3.Text = "-";
                }
                else
                {
                    cpklist3 = Array.ConvertAll(SaveStatic.ReadTxt(GlobalValues.PathVariable.fileCPK_3), Convert.ToSingle);
                    if (cpklist3.Count() > 2)
                    {
                        cpk3 = cpkpro.GetCPK(cpklist3, (float)zhuye_max, (float)zhuye_min);
                    }
                    else
                        cpk3 = 0;
                    lbCPKValue_3.Text = cpk3.ToString("0.000");
                }
                //针头2_2
                if (!File.Exists(GlobalValues.PathVariable.fileCPK_4))
                {
                    lbCPKValue_4.Text = "-";
                }
                else
                {
                    cpklist4 = Array.ConvertAll(SaveStatic.ReadTxt(GlobalValues.PathVariable.fileCPK_4), Convert.ToSingle);
                    if (cpklist4.Count() > 2)
                    {
                        cpk4 = cpkpro.GetCPK(cpklist4, (float)zhuye_max, (float)zhuye_min);
                    }
                    else
                        cpk4 = 0;
                    lbCPKValue_4.Text = cpk4.ToString("0.000");
                }
                //针头3_1
                if (!File.Exists(GlobalValues.PathVariable.fileCPK_5))
                {
                    lbCPKValue_5.Text = "-";
                }
                else
                {
                    cpklist5 = Array.ConvertAll(SaveStatic.ReadTxt(GlobalValues.PathVariable.fileCPK_5), Convert.ToSingle);
                    if (cpklist5.Count() > 2)
                    {
                        cpk5 = cpkpro.GetCPK(cpklist4, (float)zhuye_max, (float)zhuye_min);
                    }
                    else
                        cpk5 = 0;
                    lbCPKValue_5.Text = cpk5.ToString("0.000");
                }
                //针头3_2
                if (!File.Exists(GlobalValues.PathVariable.fileCPK_6))
                {
                    lbCPKValue_6.Text = "-";
                }
                else
                {
                    cpklist6 = Array.ConvertAll(SaveStatic.ReadTxt(GlobalValues.PathVariable.fileCPK_6), Convert.ToSingle);
                    if (cpklist6.Count() > 2)
                    {
                        cpk6 = cpkpro.GetCPK(cpklist4, (float)zhuye_max, (float)zhuye_min);
                    }
                    else
                        cpk6 = 0;
                    lbCPKValue_6.Text = cpk6.ToString("0.000");
                }
            }
            catch (Exception ex)
            {
                GlobalValues.log_Helper.DispProcess("CPK扫描Timer ： " + ex, "Alarm", true);
            }
        }


        private void tCPKOffset_Tick(object sender, EventArgs e)
        {
            try
            {
                if (File.Exists(GlobalValues.PathVariable.fileCPK_1))
                {
                    string[] CPKValue1 = SaveStatic.ReadTxt(GlobalValues.PathVariable.fileCPK_1);
                    if (CPKValue1.Count() >= GlobalValues.CommonVariable.closedLoopTRAS)
                    {
                        float[] zhuye1 = Array.ConvertAll(CPKValue1, Convert.ToSingle);
                        float NoteLiquidOffset1 = (float)(zhuye_max + zhuye_min) / 2 - zhuye1.Average();
                        lbCPKOffset_1.Text = NoteLiquidOffset1.ToString("0.000");

                        //把值写给PLC
                        GlobalValues.njOmronPLC.WriteVariable(GlobalValues.PLCVariableName.neddle_1Offset, NoteLiquidOffset1);
                        //触发PLC去补偿
                        GlobalValues.njOmronPLC.WriteVariable(GlobalValues.PLCVariableName.neddle_1OffsetTrigger, 1);
                        GlobalValues.log_Helper.DispProcess("注液头1补偿：" + NoteLiquidOffset1.ToString("0.000"), "Info", true);
                        SaveStatic.SaveTxt(GlobalValues.PathVariable.fileCPK_Offset_1, "Offset : " + NoteLiquidOffset1.ToString("0.000") + "\r\n" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\r\n", true);//保存offset数据

                        FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_1, GlobalValues.PathVariable.fileCPK_1.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                        SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_1);     //清空文本文件
                    }
                }
                else
                {
                    lbCPKOffset_1.Text = "-";
                }

                if (File.Exists(GlobalValues.PathVariable.fileCPK_2))
                {
                    string[] CPKValue2 = SaveStatic.ReadTxt(GlobalValues.PathVariable.fileCPK_2);
                    if (CPKValue2.Count() >= GlobalValues.CommonVariable.closedLoopTRAS)
                    {
                        float[] zhuye2 = Array.ConvertAll(CPKValue2, Convert.ToSingle);
                        float NoteLiquidOffset2 = (float)(zhuye_max + zhuye_min) / 2 - zhuye2.Average();
                        lbCPKOffset_2.Text = NoteLiquidOffset2.ToString("0.000");
                        //把值写给PLC
                        GlobalValues.njOmronPLC.WriteVariable(GlobalValues.PLCVariableName.neddle_2Offset, NoteLiquidOffset2);
                        //触发PLC去补偿
                        GlobalValues.njOmronPLC.WriteVariable(GlobalValues.PLCVariableName.neddle_2OffsetTrigger, 1);

                        GlobalValues.log_Helper.DispProcess("注液头2补偿：" + NoteLiquidOffset2.ToString("0.000"), "Info", true);
                        SaveStatic.SaveTxt(GlobalValues.PathVariable.fileCPK_Offset_2, "Offset : " + NoteLiquidOffset2.ToString("0.000") + "\r\n" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\r\n", true);//保存offset数据

                        FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_2, GlobalValues.PathVariable.fileCPK_2.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                        SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_2);     //清空文本文件
                    }
                }
                else
                {
                    lbCPKOffset_2.Text = "-";
                }


                if (File.Exists(GlobalValues.PathVariable.fileCPK_3))
                {
                    string[] CPKValue3 = SaveStatic.ReadTxt(GlobalValues.PathVariable.fileCPK_3);
                    if (CPKValue3.Count() >= GlobalValues.CommonVariable.closedLoopTRAS)
                    {
                        float[] zhuye3 = Array.ConvertAll(CPKValue3, Convert.ToSingle);
                        float NoteLiquidOffset3 = (float)(zhuye_max + zhuye_min) / 2 - zhuye3.Average();
                        lbCPKOffset_3.Text = NoteLiquidOffset3.ToString("0.000");
                        //把值写给PLC
                        GlobalValues.njOmronPLC.WriteVariable(GlobalValues.PLCVariableName.neddle_3Offset, NoteLiquidOffset3);
                        //触发PLC去补偿
                        GlobalValues.njOmronPLC.WriteVariable(GlobalValues.PLCVariableName.neddle_3OffsetTrigger, 1);

                        GlobalValues.log_Helper.DispProcess("注液头3补偿：" + NoteLiquidOffset3.ToString("0.000"), "Info", true);
                        SaveStatic.SaveTxt(GlobalValues.PathVariable.fileCPK_Offset_3, "Offset : " + NoteLiquidOffset3.ToString("0.000") + "\r\n" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\r\n", true);//保存offset数据

                        FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_3, GlobalValues.PathVariable.fileCPK_3.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                        SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_3);     //清空文本文件
                    }
                }
                else
                {
                    lbCPKOffset_3.Text = "-";
                }

                if (File.Exists(GlobalValues.PathVariable.fileCPK_4))
                {
                    string[] CPKValue4 = SaveStatic.ReadTxt(GlobalValues.PathVariable.fileCPK_4);
                    if (CPKValue4.Count() >= GlobalValues.CommonVariable.closedLoopTRAS)
                    {
                        float[] zhuye4 = Array.ConvertAll(CPKValue4, Convert.ToSingle);
                        float NoteLiquidOffset4 = (float)(zhuye_max + zhuye_min) / 2 - zhuye4.Average();
                        lbCPKOffset_4.Text = NoteLiquidOffset4.ToString("0.000");
                        //把值写给PLC
                        GlobalValues.njOmronPLC.WriteVariable(GlobalValues.PLCVariableName.neddle_4Offset, NoteLiquidOffset4);
                        //触发PLC去补偿
                        GlobalValues.njOmronPLC.WriteVariable(GlobalValues.PLCVariableName.neddle_4OffsetTrigger, 1);

                        GlobalValues.log_Helper.DispProcess("注液头4补偿：" + NoteLiquidOffset4.ToString("0.000"), "Info", true);
                        SaveStatic.SaveTxt(GlobalValues.PathVariable.fileCPK_Offset_4, "offset : " + NoteLiquidOffset4.ToString("0.000") + "\r\n" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\r\n", true);//保存offset数据

                        FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_4, GlobalValues.PathVariable.fileCPK_4.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                        SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_4);     //清空文本文件
                    }
                }
                else
                {
                    lbCPKOffset_4.Text = "-";
                }

                if (File.Exists(GlobalValues.PathVariable.fileCPK_5))
                {
                    string[] CPKValue5 = SaveStatic.ReadTxt(GlobalValues.PathVariable.fileCPK_5);
                    if (CPKValue5.Count() >= GlobalValues.CommonVariable.closedLoopTRAS)
                    {
                        float[] zhuye5 = Array.ConvertAll(CPKValue5, Convert.ToSingle);
                        float NoteLiquidOffset5 = (float)(zhuye_max + zhuye_min) / 2 - zhuye5.Average();
                        lbCPKOffset_5.Text = NoteLiquidOffset5.ToString("0.000");
                        //把值写给PLC
                        GlobalValues.njOmronPLC.WriteVariable(GlobalValues.PLCVariableName.neddle_5Offset, NoteLiquidOffset5);
                        //触发PLC去补偿
                        GlobalValues.njOmronPLC.WriteVariable(GlobalValues.PLCVariableName.neddle_5OffsetTrigger, 1);

                        GlobalValues.log_Helper.DispProcess("注液头5补偿：" + NoteLiquidOffset5.ToString("0.000"), "Info", true);
                        SaveStatic.SaveTxt(GlobalValues.PathVariable.fileCPK_Offset_5, "offset : " + NoteLiquidOffset5.ToString("0.000") + "\r\n" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\r\n", true);//保存offset数据

                        FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_5, GlobalValues.PathVariable.fileCPK_5.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                        SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_5);     //清空文本文件
                    }
                }
                else
                {
                    lbCPKOffset_5.Text = "-";
                }

                if (File.Exists(GlobalValues.PathVariable.fileCPK_6))
                {
                    string[] CPKValue6 = SaveStatic.ReadTxt(GlobalValues.PathVariable.fileCPK_6);
                    if (CPKValue6.Count() >= GlobalValues.CommonVariable.closedLoopTRAS)
                    {
                        float[] zhuye6 = Array.ConvertAll(CPKValue6, Convert.ToSingle);
                        float NoteLiquidOffset6 = (float)(zhuye_max + zhuye_min) / 2 - zhuye6.Average();
                        lbCPKOffset_6.Text = NoteLiquidOffset6.ToString("0.000");
                        //把值写给PLC
                        GlobalValues.njOmronPLC.WriteVariable(GlobalValues.PLCVariableName.neddle_6Offset, NoteLiquidOffset6);
                        //触发PLC去补偿
                        GlobalValues.njOmronPLC.WriteVariable(GlobalValues.PLCVariableName.neddle_6OffsetTrigger, 1);

                        GlobalValues.log_Helper.DispProcess("注液头6补偿：" + NoteLiquidOffset6.ToString("0.000"), "Info", true);
                        SaveStatic.SaveTxt(GlobalValues.PathVariable.fileCPK_Offset_6, "offset : " + NoteLiquidOffset6.ToString("0.000") + "\r\n" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\r\n", true);//保存offset数据

                        FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_6, GlobalValues.PathVariable.fileCPK_6.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                        SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_6);     //清空文本文件
                    }
                }
                else
                {
                    lbCPKOffset_6.Text = "-";
                }
            }
            catch (Exception ex)
            {
                GlobalValues.log_Helper.DispProcess("CPK补偿值扫描Timer ： " + ex, "Alarm", true);
            }
        }
        /// <summary>
        /// 主界面 补偿值 显示删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClearCPKOffset_Click(object sender, EventArgs e)
        {
            if (File.Exists(GlobalValues.PathVariable.fileCPK_Offset_1))
            {
                //FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_Offset_1, GlobalValues.PathVariable.fileCPK_Offset_1.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                //SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_Offset_1);     //清空文本文件
                lbCPKOffset_1.Text = "-";
            }

            if (File.Exists(GlobalValues.PathVariable.fileCPK_Offset_2))
            {
                //FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_Offset_2, GlobalValues.PathVariable.fileCPK_Offset_2.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                //SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_Offset_2);     //清空文本文件
                lbCPKOffset_2.Text = "-";
            }

            if (File.Exists(GlobalValues.PathVariable.fileCPK_Offset_3))
            {
                //FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_Offset_3, GlobalValues.PathVariable.fileCPK_Offset_4.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                //SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_Offset_3);     //清空文本文件
                lbCPKOffset_3.Text = "-";
            }

            if (File.Exists(GlobalValues.PathVariable.fileCPK_Offset_4))
            {
                //FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_Offset_4, GlobalValues.PathVariable.fileCPK_Offset_4.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                //SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_Offset_4);     //清空文本文件
                lbCPKOffset_4.Text = "-";
            }

            if (File.Exists(GlobalValues.PathVariable.fileCPK_Offset_5))
            {
                //FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_Offset_5, GlobalValues.PathVariable.fileCPK_Offset_5.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                //SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_Offset_5);     //清空文本文件
                lbCPKOffset_5.Text = "-";
            }

            if (File.Exists(GlobalValues.PathVariable.fileCPK_Offset_6))
            {
                //FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_Offset_6, GlobalValues.PathVariable.fileCPK_Offset_6.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                //SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_Offset_6);     //清空文本文件
                lbCPKOffset_6.Text = "-";
            }
        }



        /// <summary>
        /// 主界面 CPK值删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClearCPK_Click(object sender, EventArgs e)
        {
            if (File.Exists(GlobalValues.PathVariable.fileCPK_1))
            {
                FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_1, GlobalValues.PathVariable.fileCPK_1.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_1);     //清空文本文件
                lbCPKValue_1.Text = "-";
            }


            if (File.Exists(GlobalValues.PathVariable.fileCPK_2))
            {
                FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_2, GlobalValues.PathVariable.fileCPK_2.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_2);     //清空文本文件
                lbCPKValue_2.Text = "-";
            }

            if (File.Exists(GlobalValues.PathVariable.fileCPK_3))
            {
                FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_3, GlobalValues.PathVariable.fileCPK_3.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_3);     //清空文本文件
                lbCPKValue_3.Text = "-";
            }

            if (File.Exists(GlobalValues.PathVariable.fileCPK_4))
            {
                FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_4, GlobalValues.PathVariable.fileCPK_4.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_4);     //清空文本文件
                lbCPKValue_4.Text = "-";
            }

            if (File.Exists(GlobalValues.PathVariable.fileCPK_5))
            {
                FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_5, GlobalValues.PathVariable.fileCPK_5.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_5);     //清空文本文件
                lbCPKValue_5.Text = "-";
            }

            if (File.Exists(GlobalValues.PathVariable.fileCPK_6))
            {
                FileAct.TransfFile(GlobalValues.PathVariable.fileCPK_6, GlobalValues.PathVariable.fileCPK_6.Insert(37, "_" + DateTime.Now.ToString("HH_mm_ss")));//保留一份CPK的数据作为备份
                SaveStatic.ClearTxt(GlobalValues.PathVariable.fileCPK_6);     //清空文本文件
                lbCPKValue_6.Text = "-";
            }
        }






        private void button5_Click(object sender, EventArgs e)
        {
            GlobalValues.productDataAcq.Test();
        }


        private void button6_Click(object sender, EventArgs e)
        {
            GlobalValues.productDataAcq.Test3();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            GlobalValues.productDataAcq.Test2();
        }

        private void button13_Click(object sender, EventArgs e)
        {
            GlobalValues.productDataAcq.Test4();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            GlobalValues.productDataAcq.Test();
            GlobalValues.productDataAcq.Test2();
        }


        private void button12_Click(object sender, EventArgs e)
        {
            GlobalValues.productDataAcq.Test3();
            GlobalValues.productDataAcq.Test4();
        }

        Timer tt = new Timer();


        private void button14_Click(object sender, EventArgs e)
        {
            tt.Interval = 1000;
            tt.Tick += timer1_Tick;
            tt.Start();
        }

        private void button15_Click(object sender, EventArgs e)
        {
            tt.Stop();
        }

        int xxx = 0;
        int yyy = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (yyy < 5)
            {
                GlobalValues.productDataAcq.Test();
                GlobalValues.productDataAcq.Test3();
                yyy++;
            }
            else
            {
                if (xxx % 3 == 0)
                {
                    GlobalValues.productDataAcq.Test();
                    GlobalValues.productDataAcq.Test2();
                }
                else if (xxx % 3 == 1)
                {
                    GlobalValues.productDataAcq.Test3();
                    GlobalValues.productDataAcq.Test4();
                }
                else
                {
                    GlobalValues.productDataAcq.Test();
                    GlobalValues.productDataAcq.Test3();
                    GlobalValues.productDataAcq.Test2();
                    GlobalValues.productDataAcq.Test4();
                }
                xxx++;
            }
        }


    }
}
